package com.hn658.user.itf;

import java.util.List;
import java.util.Map;


import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.hn658.base.service.api.define.enums.ResponseCode;
import com.hn658.framework.cache.message.MessageCache;
import com.hn658.framework.dataaccess.pagination.GenericPage;
import com.hn658.framework.shared.exception.BusinessException;
import com.hn658.framework.shared.utils.BeanMapper;
import com.hn658.user.appinfo.service.IAppInfoService;
import com.hn658.user.common.entity.AppInfoEO;
import com.hn658.user.itf.vo.AppInfoDTO;
import com.hn658.user.itf.vo.AppInfoResponse;

/**
 * <p>
 * 描述：用户模块的开放服务实现
 * </p>
 * 
 * @ClassName UserServiceImpl
 * @author ztjie
 * @date 2014-8-5 下午3:14:09
 */
public class ItfAppInfoServiceImpl implements ItfAppInfoService {
	
	@Autowired
	private IAppInfoService appInfoService;
	
	@Autowired
	private MessageCache messageCache;

	@Override
	public AppInfoResponse findAppInfoByAppId(String appId) {
		AppInfoResponse response = new AppInfoResponse();
		try {
			AppInfoEO app = appInfoService.findAppByAppId(appId);
			AppInfoDTO appInfo = new AppInfoDTO();
			BeanUtils.copyProperties(app, appInfo);
			response.setAppInfo(appInfo);
			response.setCode(ResponseCode.IsSuccess);
		} catch (BusinessException e) {
			response.setCode(ResponseCode.IsError);
			response.setMessage(messageCache.getMessage(e.getErrorCode()));
		}
		return response;
	}

	@Override
	public AppInfoResponse findAppInfoPageByMap(Map<String, Object> queryMap,
			int pageSize, int start) {
		AppInfoResponse response = new AppInfoResponse();
		try {
			GenericPage<AppInfoEO> queryAppInfo = appInfoService.queryAppInfo(queryMap, pageSize, start, "id", false);
			List<AppInfoDTO> dtoList=null;
			if(queryAppInfo.getData()!=null){
				dtoList=BeanMapper.mapList(queryAppInfo.getData(), AppInfoDTO.class);
			}
			response.setAppInfoList(dtoList);
			response.setTotalCount(queryAppInfo.getTotalCount());
		} catch (BusinessException e) {
			response.setCode(ResponseCode.IsError);
			response.setMessage(messageCache.getMessage(e.getErrorCode()));
		}
		return response;
	}
	
	
}
